package alipay

import (
	"encoding/base64"

	"open/pkg/crypto"
)

// DecryptContent 解密消息内容
func DecryptContent(encryptContent, encryptKey string) (content []byte, err error) {
	var encryptedBytes []byte
	encryptedBytes, err = base64.StdEncoding.DecodeString(encryptContent)
	if err != nil {
		return
	}
	key, err := base64.StdEncoding.DecodeString(encryptKey)
	if err != nil {
		return nil, err
	}
	content, err = crypto.AesDecrypt(encryptedBytes, key)
	if err != nil {
		return nil, err
	}
	return
}

func EncryptContent(bizContent, aseKey string) (string, error) {
	key, err := base64.StdEncoding.DecodeString(aseKey)
	if err != nil {
		return "", err
	}
	ciphertext, err := crypto.AesEncrypt([]byte(bizContent), key)
	if err != nil {
		return "", err
	}
	encrypt := base64.StdEncoding.EncodeToString(ciphertext)
	return encrypt, nil
}
